aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/pot/[name]/withdraw/+page.server.js
blob: ab56867d7b6bf9a2b4f9f4979fd82cf0e8859995 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { fail, redirect } from '@sveltejs/kit';
import { auth, post } from '$lib/utils';

export async function load({ parent }) {
	let { user } = await parent();
	if (!user) throw redirect(307, '/register');
}

export const actions = {
	default: async ({ cookies, request }) => {
		let body = Object.fromEntries(await request.formData());

		try {
			await post('/take', body, auth(cookies));
		} catch (e) {
			return fail(400, { message: e.message });
		}

		throw redirect(307, `/pot/${body.name}`);
	}
};